<template>
  <div class="details">
    <component
      :is="MessageCard"
      ref="MessageCard"
      :enum-name="enumName"
      @getDEtail="getDEtail"
    />
    <component
      :is="PlaceMessage"
      ref="PlaceMessage"
      :enum-name="enumName"
      @getDEtail="getDEtail"
    >
      <component
        :is="TableCard"
        ref="TableCard"
        slot="place"
        enum-name="ownerLocation"
        :else-text="totalText"
        @render="render"
      />
    </component>
  </div>
</template>

<script>
import MessageCard from '@/components/MessageCard'
import PlaceMessage from '@/components/PlaceMessage'
import TableCard from '@/components/TableCard'
import { getOwnerDetail, getOwner, getOwnerLocation } from '@/api/owner'

export default {
  components: {
    MessageCard,
    PlaceMessage
  },
  data() {
    return {
      MessageCard,
      PlaceMessage,
      TableCard,
      enumName: 'owner',
      goodsTotal: 0,
      total: '',
      //   btnData3: { name: '增加货主', show: true, displaced: true },
      data: {
        ownerId: this.$route.params.value,
        id: ''
      }
    }
  },
  computed: {
    totalText() {
      return `总计：${this.total}个库位${this.goodsTotal}个 货品`
    }
  },
  async created() {
    await this.render()
  },
  methods: {
    // 根据id获取详情 编辑
    async getDEtail() {
      const { data } = await getOwner(this.$route.params.value)
      console.log(data.province, data.city, data.area)
      for (const key in data) {
        this.$set(this.$refs.MessageCard.formData, key, data[key])
      }
    },
    // 渲染页面方法（获取数据）
    async render(params = {}) {
      const res = await getOwnerDetail(this.data.ownerId)
      this.goodsTotal = res.data.goodsTotal
      const { data } = await getOwnerLocation({
        ...this.data,
        size: params.size ? params.size : 10,
        current: params.current ? params.current : 1
      })
      this.$refs.TableCard.basicData = data.records
      this.length = data.records.length
      this.$refs.TableCard.total = +data.total
      this.total = +data.total
      this.$refs.TableCard.size = +data.size
      this.$refs.TableCard.current = +data.current
    }
  }
}
</script>

<style>
</style>
